import router from '@system.router'

export default {
    data: {
        rotate: '0deg',
        timer: '',
        level: 0,
        delay: 0
    },

    onInit() {

    },

    fan(){
         return setInterval( () => {
            if(this.rotate === '0deg'){
                this.rotate = '180deg';
            }else{
                this.rotate = '0deg';
            }
        }, this.delay )
    },

    open(){
        this.level = 1;
        this.delay = 150;
        clearInterval(this.timer);
        this.timer = this.fan();
    },

    close(){
        this.level = 0;
        this.delay = 0;
        clearInterval(this.timer);
        this.timer = null;
        return;
    },

    increment(){
        if(this.level === 0){
            return;
        }
        if(this.level === 3){
            return;
        }
        this.level++;
        this.delay = 200 - 50*this.level;
        clearInterval(this.timer);
        this.timer = this.fan();
    },

    decrement(){
        if(this.level === 0){
            return;
        }
        this.level--;
        if(this.level === 0){
            this.close();
            return;
        }
        this.delay = 200 - 50*this.level;
        clearInterval(this.timer);
        this.timer = this.fan();
    }


}
